#include <stdio.h>
void fun1(int x, int *begin, int *end)
{
    for (; begin != end; begin++)
    {
        *begin = x % 10;
        x /= 10;
    }
}
int fun(int x, int y, int z)
{
    int a[9], book[10] = {0};
    fun1(x, a, a + 3);
    fun1(y, a + 3, a + 6);
    fun1(z, a + 6, a + 9);
    for (int i = 0; i < 9; i++)
    {
        book[a[i]]++;
    }
    for (int i = 0; i < 10; i++)
    {
        if (book[i] > 1)
        {
            return 0;
        }
    }
    return 1;
}
void printArray(int *begin, int *end)
{
    for (; begin != end; begin++)
        printf("%d ", *begin);
    printf("\n");
}
/*
p35页 用1-9组成3个三位数，每个数恰好使用一次，要求 abc:def:ghi = 1:2:3
我把时间复杂度为O(n^5)的程序优化成了O(n^2)
*/
int main()
{
    for (int i = 111; i <= 999; i++)
    {
        if (fun(i, i * 2, i * 3) == 1)
            printf("%d %d %d\n", i, i*2, i * 3);
    }
    return 0;
}